package com.JFapp.controller;


import com.JFapp.domain.dto.ArticleDto;
import com.JFapp.domain.dto.ArticleStatusDto;
import com.JFapp.domain.entity.Article;
import com.JFapp.domain.entity.ResponseResult;
import com.JFapp.eumns.AppHttpCodeEnum;
import com.JFapp.exception.SystemException;
import com.JFapp.service.ArticleService;
import com.JFapp.service.RoleService;
import com.JFapp.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
@Api(tags = "文章管理")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    @Autowired
    private RoleService roleService;

    @ApiOperation("写文章")
    @PostMapping()
    public ResponseResult writeArticle(@RequestBody @Validated ArticleDto article){
        return articleService.writeArticle(article);
    }
   @ApiOperation("查询文章列表")
   @GetMapping("/list")
    public ResponseResult getArticleList(Integer pageNum ,Integer pageSize){
        return articleService.getArticleList(pageNum,pageSize);
   }
   @ApiOperation("查询文章细节")
   @GetMapping("/{id}")
   @PreAuthorize("@ps.hasPermission('content:article:writer')")
   public ResponseResult getArticleDetail(@PathVariable Long id){
        return articleService.getDetailById(id);
   }

   @PutMapping()
   public ResponseResult updateArticle(@RequestBody ArticleDto articleDto){
        return articleService.updateArticle(articleDto);
   }

    @PutMapping("/changeStatus")
    public  ResponseResult updateArticleStatus(@RequestBody ArticleStatusDto articleStatusDto){
        return articleService.updateArticleStatus(articleStatusDto);
    }

   @ApiOperation("删除文章")
   @DeleteMapping("/{id}")
    public ResponseResult deleteArticle(@PathVariable Long id){
       return articleService.deleteArticle(id);
   }
}
